package folderLogger.fileFilters;

import java.io.File;
import java.io.FileFilter;

public class ExtensionIncludeFilter implements FileFilter {
	
private String[] supportedExtensions; 	
private int extensionsCount;
	
	public ExtensionIncludeFilter(String[] supportedExtensions)
	{
		this.supportedExtensions = supportedExtensions;
		extensionsCount = supportedExtensions.length;
	}


	@Override
	public boolean accept(File currentFile) {
		String fileExtension = getExtension(currentFile);
		for(int i=0; i<extensionsCount; i++)
		{
			if(fileExtension.equalsIgnoreCase(supportedExtensions[i]))
			{
				return true;
			}
		}
		return false;
	}
	
	public String getExtension(File file)
	{
		String fileName = file.getName();
		int extensionIndex = fileName.lastIndexOf('.');
		return extensionIndex == -1 ? "" : fileName.substring(extensionIndex+1);
	}
}